package org.rcy.framework.job.elastic;


import com.dangdang.ddframe.job.api.simple.SimpleJob;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 吴康桥
 * @Description
 * @date 2022/12/7 17:47
 */


public abstract  class SimpleElasticJob implements SimpleJob {
	private String cron;
	private static final int DEFAULT_SHARDING_TOTAL_COUNT = 1;
	private int shardingTotalCount;

	protected SimpleElasticJob(String cron) {
		this.cron = cron;
		this.shardingTotalCount = 1;
	}

	protected SimpleElasticJob(String cron, int shardingTotalCount) {
		this.cron = cron;
		if (shardingTotalCount < 1) {
			this.shardingTotalCount = 1;
		} else if (shardingTotalCount > 10) {
			this.shardingTotalCount = 10;
		} else {
			this.shardingTotalCount = shardingTotalCount;
		}

	}

	public String getCron() {
		return this.cron;
	}

	public int getShardingTotalCount() {
		return this.shardingTotalCount;
	}

	public List<Integer> getEndIndexs(List<Integer> list) {
		List<Integer> result = new ArrayList();

		for(int i = 0; i < 10; ++i) {
			if (list.contains(i % this.shardingTotalCount)) {
				result.add(i);
			}
		}

		return result;
	}
}
